<?php
class InfoAction extends Action {

    public function _initialize() {
        $Setting = M('Setting');
        $setting = $Setting->find(1);
        
        $this->assign('setting', $setting);
    }
    
    public function entry() {
        if (isset($_GET['id'])) {
            $id = (int) $_GET['id'];
        }
        $Article = M('Article');
        $detail = $Article->find($id);
        $detail['hits'] = $detail['hits'] + 1;
        $Article->save($detail);
        $other = $Article->where(array('cat_id' => $detail['cat_id']))->order(array('list_order' => 'asc', 'article_id' => 'desc'))->select();
        
        $Category = M('category');
        $category = $Category->find($detail['cat_id']);
        
        $this->assign('detail', $detail);
        $this->assign('other', $other);
        $this->assign('category', $category);
        $this->display();
    }
    
    public function category() {
    	if (isset($_GET['id'])) {
            $id = (int) $_GET['id'];
	    	$Article = M('Article');
            import("ORG.Util.Page");
            import("ORG.Util.PageNav");

            $count = $Article->where(array('cat_id' => $id))->count();
            $Page = new PageNav($count, 25);
            $Page->setConfig('theme', '<li>%upPage%</li> <li id="n_num">%nowPage%/%totalPage%</li> <li>%downPage%</li>');
            $show = $Page->show();
            $this->assign('page',$show);
            
	        $article = $Article->where(array('cat_id' => $id))->order(array('list_order' => 'asc', 'article_id' => 'desc'))->limit($Page->firstRow . ',' . $Page->listRows)->select();
            
            $Category = M('Category');
            $category = $Category->find($id);
            
            $this->assign('article', $article);
            $this->assign('category', $category);
	        $this->display();
        } else {
            $this->error();
        }
    }
    
}
?>